package kevin.framework.basic.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import kevin.framework.basic.dao.IBaseDao;
import kevin.framework.basic.service.impl.BaseService;
import kevin.framework.basic.dao.IRoleFuncDao;
import kevin.framework.basic.domain.RoleFunc;

import kevin.framework.basic.service.IRoleFuncService;

/**
*Generate by Kevin's CodeBuilder
**/
@Service
public class RoleFuncService extends BaseService<RoleFunc, String> implements IRoleFuncService {

		private static final long serialVersionUID = -1L;

		private  IRoleFuncDao roleFuncDao;

		@Resource(name="roleFuncDao")
		@Override
		public void setDao(IBaseDao<RoleFunc, String> dao) {
				this.dao = dao;
				roleFuncDao = (IRoleFuncDao)dao;
		}
		
		@Override
		public void setRoleFunc(String roleId, List<RoleFunc> list, String menus) throws Exception {
			
			List<String> menuIdList = new ArrayList<String>();
			String [] tmp = menus.split(",");
			for(String id : tmp) {
				menuIdList.add(id);
			}
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("roleId", roleId);
			if(menuIdList.size() > 0) {
				param.put("menuIds", menuIdList);
			}
			this.deleteParam(param);
			
			for(RoleFunc rf : list) {
				rf.setRoleId(roleId);
				this.insert(rf);
			}
		}
		
		
		
}
